package com.then.component.login.repository;

import android.arch.lifecycle.LiveData;

import com.blankj.utilcode.util.EncryptUtils;
import com.then.architecture.AppExecutors;
import com.then.architecture.data.dto.SimpleEntity;
import com.then.architecture.data.request.BaseReq;
import com.then.component.login.api.RemoteService;
import com.then.architecture.di.AppScope;
import com.then.architecture.data.repository.BaseRepository;
import com.then.architecture.data.dto.Resource;
import com.then.component.login.dto.Auth;
import com.then.component.login.dto.Login;
import com.then.component.login.dto.LoginSimpleEntity;
import com.then.component.login.request.CheckNickNameReq;
import com.then.component.login.request.CompleteFindPwdReq;
import com.then.component.login.request.CompleteRegisterReq;
import com.then.component.login.request.FindPwdReq;
import com.then.component.login.request.LoginByPhoneReq;
import com.then.component.login.request.RegisterReq;


import javax.inject.Inject;

/**
 * Created by 42524 on 2018/1/9.
 */
@AppScope
public class LoginRepository extends BaseRepository<RemoteService> {


    @Inject
    public LoginRepository(AppExecutors appExecutors, RemoteService remoteService) {
        super(appExecutors, remoteService);
    }


    public LiveData<Resource<Login>> login(String phone, String pwd) {
        return call(remoteService.login(new LoginByPhoneReq(phone, EncryptUtils.encryptMD5ToString(pwd).toLowerCase())));
    }

    public LiveData<Resource<LoginSimpleEntity>> isPhoneRegistered(BaseReq req) {
        return call(remoteService.isPhoneRegistered(req.toMap()));
    }


    public LiveData<Resource<LoginSimpleEntity>> sendSms(BaseReq req) {
        return call(remoteService.sendSms(req.toMap()));
    }

    public LiveData<Resource<Auth>> register(RegisterReq registerReq) {
        return call(remoteService.register(registerReq));
    }

    public LiveData<Resource<Login>> completePhoneFindPwd(CompleteFindPwdReq completeFindPwdReq) {
        return call(remoteService.completePhoneFindPwd(completeFindPwdReq));
    }

    public LiveData<Resource<Auth>> findPwd(FindPwdReq findPwdReq) {
        return call(remoteService.findPwd(findPwdReq));
    }

    public LiveData<Resource<SimpleEntity>> completeRegister(CompleteRegisterReq completeRegisterReq) {
        return call(remoteService.completeRegister(completeRegisterReq));
    }

    public LiveData<Resource<SimpleEntity>> checkNickname(CheckNickNameReq nickNameReq) {
        return call(remoteService.checkNickName(nickNameReq.toMap()));
    }

}
